Setting Environment Variables in Linux: A Beginner's Guide
This article introduces the core knowledge of Linux environment variables. Environment variables are variables that store system or program runtime information, such as software paths, language settings, etc. They allow the system to "remember" configurations without repeatedly entering complex information. Setting environment variables is mainly used to enable the system to locate executable programs (such as the PATH variable) or to control language, user information, etc. To view variables: use `echo $VARIABLE_NAME` for a single variable, and `env` or `printenv` for all variables. Temporary settings (valid only in the current terminal) use `export VARIABLE_NAME=value`, for example, `export MY_VAR="hello"`. For permanent settings, there are user-level configurations (modify `~/.bashrc` or `~/.profile` and require `source` to take effect) and system-level configurations (requires `sudo` to modify files like `/etc/profile`, applicable to all users). The `PATH` variable is critical, as it lists the paths the system searches for executable files. To temporarily add a path, use `export PATH=$PATH:/new/path`, and permanent configuration follows the same logic. Common variables also include `HOME` (home directory), `LANG` (language), etc. Note: Use `export` for temporary settings and configuration files for permanent ones; `sudo` is required for system-level modifications; variable values... (Note: The original text ends abruptly here.)
Read More